package com.qfedu.controller;

import com.qfedu.common.JsonResult;
import com.qfedu.entity.User;
import com.qfedu.service.UserService;
import com.qfedu.utils.StrUtils;
import com.sun.tools.internal.xjc.reader.xmlschema.bindinfo.BIConversion;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * projectName: carCourier
 * author: CGY
 * time: 2020/9/19 11:31
 * description:用户修改信息
 */
@Controller
@RequestMapping("/user")
@ResponseBody
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * 修改用户基本信息
     * @param email
     * @param session
     * @return
     */
    @RequestMapping("/update.do")
    public JsonResult updateById(String email, HttpSession session){
        User user = (User) session.getAttribute(StrUtils.LOGIN_USER);
        user.setEmail(email);
        userService.updateById(user);
        return new JsonResult(1,"修改信息成功");
    }

    /**
     * 修改用户密码
     * @param password
     * @param session
     * @return
     */
    @RequestMapping("/modifypassword.do")
    public JsonResult update(String password,HttpSession session){
        User user = (User) session.getAttribute(StrUtils.LOGIN_USER);
        user.setPassword(password);
        userService.updatePassword(user);
        return new JsonResult(1,"修改密码成功");
    }
}
